package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.MesSaleOrderChange;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.MesSaleOrderChangeDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-09-08 15:57:41
 */
public class MesSaleOrderChangeConverts {

    private static Logger LOG = LoggerFactory.getLogger(MesSaleOrderChangeConverts.class);

    public static List<MesSaleOrderChangeDTO> convert(List<MesSaleOrderChange> mesSaleOrderChangeList) {
        if (CollectionUtils.isEmpty(mesSaleOrderChangeList)) {
            return Collections.EMPTY_LIST;
        }

        List<MesSaleOrderChangeDTO> mesSaleOrderChangeListResult = Lists.newArrayList();
        for (MesSaleOrderChange mesSaleOrderChange : mesSaleOrderChangeList) {
            mesSaleOrderChangeListResult.add(convert(mesSaleOrderChange));
        }
        return mesSaleOrderChangeListResult;
    }

    public static MesSaleOrderChangeDTO convert(MesSaleOrderChange mesSaleOrderChange) {
        try {
            return BeanUtils.copy(mesSaleOrderChange, MesSaleOrderChangeDTO.class);
        } catch (Exception e) {
            LOG.error("MesSaleOrderChange到MesSaleOrderChangeDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesSaleOrderChange到MesSaleOrderChangeDTO转换失败", e);
        }
    }

    public static MesSaleOrderChange convert(MesSaleOrderChangeDTO mesSaleOrderChangeDTO) {
        try {
            return BeanUtils.copy(mesSaleOrderChangeDTO, MesSaleOrderChange.class);
        } catch (Exception e) {
            LOG.error("MesSaleOrderChangeDTO到MesSaleOrderChange转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesSaleOrderChangeDTO到MesSaleOrderChange转换失败", e);
        }
    }
}